# Created by 黄景涛
# DATE: 2025/4/15

import requests
import logging
import warnings


def post_task(params, url, headers):
    """新增数据请求任务"""
    warnings.filterwarnings('ignore')
    try:
        response = requests.post(
            url=url,
            json=params,
            headers=headers,
            verify=False
        )
        response.raise_for_status()
        logging.info(f"请求成功: {response.json()}")
        return response.json()
    except requests.exceptions.RequestException as e:
        logging.error(f"请求失败: {str(e)}")
        return False
    except Exception as e:
        logging.error(f"系统异常: {str(e)}")
        return False


def get_task(params, url, headers):
    """新增数据请求任务"""
    try:
        response = requests.get(
            url=url,
            params=params,
            headers=headers
        )

        response.raise_for_status()
        logging.info(f"请求成功: {response.json()}")
        return response.json()
    except requests.exceptions.RequestException as e:
        logging.error(f"请求失败: {str(e)}")
        return False
    except Exception as e:
        logging.error(f"系统异常: {str(e)}")
        return False


def delete_task(params, url, headers):
    """删除数据请求任务"""
    try:
        response = requests.delete(
            url=url,
            json=params,
            headers=headers
        )
        response.raise_for_status()
        logging.info(f"请求成功: {response.json()}")
        return response.json()
    except requests.exceptions.RequestException as e:
        logging.error(f"请求失败: {str(e)}")
        return False
    except Exception as e:
        logging.error(f"系统异常: {str(e)}")
        return False
